package com.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.bean.Street;
import com.dao.StreetDao;

public class StreetDaoImpl implements StreetDao {

	@Override
	public List<Street> getAll() {
		Session session = null;
		try {
			session = HibernateUtil.getSession();
			return session.createQuery("from Street").list();
		} finally {
			if (session != null)
				session.close();
		}
	}

	@Override
	public List<Street> getStreet(int districtId) {
		Session session = null;
		try {
			session = HibernateUtil.getSession();
			Query query = session.createQuery("from Street s where s.district.id = ?");
			query.setInteger(0, districtId);
			return query.list();
		} finally {
			if (session != null)
				session.close();
		}
	}

}
